﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace com.kmxy.Common
{

    /// <summary>
    /// 提供全系统公共的操作对象及方法
    /// </summary>
    public class GlobalToolkit
    {
        /// <summary>
        /// 程序运行写日志类
        /// </summary>


        private GlobalToolkit()
        {
            IsShowPrint = false;
        }
        private static GlobalToolkit instance = null;
        private static object lockObj = new object();

        public static GlobalToolkit GetInstance()
        {
            if (instance != null) return instance;
            lock (lockObj)
            {
                if (instance == null)
                {
                    instance = new GlobalToolkit();
                }
            }
            return instance;
        }

        /// <summary>
        /// 写日志
        /// </summary>
        public void Logs(Type t, Exception e, string header, LogType type = LogType.Debug)
        {
            LogHelper.Write(t, e, header, type);
        }
        public void Logs(Type t, string message, string header, LogType type = LogType.Debug)
        {
            LogHelper.Write(t, message, header, type);
        }


        public bool IsShowPrint { get; set; }

        /// <summary>
        /// 时时消息输出
        /// </summary>        
        public void P(string msg)
        {
            if (!IsShowPrint) return;
            try
            {
                Console.WriteLine("{0}\t{1}", DateTime.Now, msg);
            }
            catch (Exception)
            {
                // ignored
            }
        }
        public void P(string format, params object[] args)
        {
            if (IsShowPrint) P(string.Format(format, args));
        }
    }

}
